package main

import (
	"fmt"
	modbus "github.com/thinkgos/gomodbus"
	"github.com/thinkgos/gomodbus/mb"
	"time"
)

func main()  {

	p := modbus.NewRTUClientProvider()

	p.Address = "COM3"

	p.BaudRate = 9600

	p.DataBits = 8

	p.Parity = "N"

	p.StopBits = 1

	p.Timeout = 100 * time.Millisecond

	client := mb.NewClient(p)

	client.LogMode(true)

	err := client.Start()

	if err != nil {
		panic(err)
	}
	// err  = client.WriteSingleRegister(1, 0, 1)
	//if err != nil {
	//	panic(err)
	//}
	value, err := client.ReadHoldingRegisters(1, 0, 1)

	if err != nil {
		fmt.Println("readHoldErr,", err)
	}
	for _,v:= range value {
		fmt.Println("v=,", v)
	}

    err  = client.WriteSingleRegister(1, 0, 0)
	if err != nil {
		panic(err)
	}
}
